package com.zhang.zhangapp.view.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.zhang.zhangapp.R;
import com.zhang.zhangapp.application.MApplication;
import com.zhang.zhangapp.base.http.MCallback;
import com.zhang.zhangapp.http.CommonHttp;
import com.zhang.zhangapp.utils.T;
import com.zhang.zhangapp.view.BaseAppCompatActivityActivity;

import org.xutils.common.Callback;
import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/4/25.
 */
@ContentView(R.layout.activity_back_us)
public class BackUsActivity extends BaseAppCompatActivityActivity {
    @ViewInject(R.id.action_bar_title)
    TextView titleText;
    @ViewInject(R.id.edit)
    EditText editText;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        titleText.setText("意见反馈");
    }

    @Event(type = View.OnClickListener.class, value = R.id.sure)
    private void sure(View view) {
        if (editText.getText().equals("")) {
            T.showShort(this, "请填写意见");
            return;
        }
        if (showLoadingDialog()) {
            Map<String, String> params = new HashMap<>();
            params.put("memberId", MApplication.getInstance().getUser().getMemberId());
            params.put("feedback", editText.getText().toString());
            CommonHttp.commonHttp("hzg/feedback/addFeedback", params, new MCallback() {
                @Override
                public void onSuccess(String data) {
                    T.showShort(BackUsActivity.this, "感谢您的意见");
                    BackUsActivity.this.finish();
                }

                @Override
                public void onSuccess(String message, String code) {

                }

                @Override
                public void onError(Throwable ex, boolean isOnCallback) {

                }

                @Override
                public void onCancelled(Callback.CancelledException cex) {

                }

                @Override
                public void onFinished() {
                    dismisionDalog();
                }
            });
        }
    }

    @Event(type = View.OnClickListener.class, value = R.id.action_bar_left_image)
    private void back(View view) {
        this.finish();
    }
}
